package com.perfma.xtest.tool;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * @author: junhui.si
 * @date: 2021-06-10 14:49
 **/
public class JsonDemo {
    public static void main(String[] args) {
        ExecConflictDescriptor execConflictDescriptor = new ExecConflictDescriptor();
        execConflictDescriptor.setRunningExecId(90859494056132609L);
        execConflictDescriptor.setRunningSceneId(90859494056132609L);
        execConflictDescriptor.setConflictExecId(90859494056132609L);
        execConflictDescriptor.setConflictSceneId(90859494056132609L);
        List<ExecConflictAppDescriptor> list = Lists.newArrayList();
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        list.add(new ExecConflictAppDescriptor(90859494056132609L, "stress_sjdfjsd_njsdfns_hsdfbnmsdbf"));
        System.out.println(JSONObject.toJSONString(list).length());
        execConflictDescriptor.getConflictAppDescriptors().addAll(list);
        String json = JSONObject.toJSONString(execConflictDescriptor);
        System.out.println(json.length());
    }

    @Data
    public static class ExecConflictDescriptor {

        private Long runningExecId;
        private Long runningSceneId;

        private final List<ExecConflictAppDescriptor> conflictAppDescriptors = Lists.newArrayList();

        public void addExecConflictAppDescriptor(ExecConflictAppDescriptor descriptor) {
            Preconditions.checkNotNull(descriptor);
            conflictAppDescriptors.add(descriptor);
        }


        private Long conflictExecId;
        private Long conflictSceneId;
        private Long conflictWorkspaceId;
        /**
         * 以下信息可以为空，用于展示信息
         */
        private String conflictSceneName;
        private String orConflictScriptName;
        private String conflictSceneExecOperator;
        private Date conflictBeginTime;
        private Date conflictEndTime;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ExecConflictAppDescriptor {
        /**
         * 冲突的【应用id】
         */
        private Long conflictClusterId;
        /**
         * 冲突的【应用名称】
         */
        private String conflictClusterName;
    }

}
